<?php


namespace app\common\tool;


use app\common\exception\BaseException;
use app\common\exception\CaptchaException;
use think\facade\Cache;

class CacheTool
{

    public function setCache($key, $value, $allowTime = 300)
    {
        if (!$key || !$value) {
            throw new CaptchaException(['msg' => '键值都不能为空']);
        }

        Cache::store('redis')->set($key, $value, $allowTime);
    }

    public function getCache($key)
    {
        return Cache::store('redis')->get($key);
    }

    public function checkCache($key, $real_key): bool
    {
        return strtoupper($this->getCache($key)) == strtoupper($real_key);
    }

    public function clearCache($key)
    {
        Cache::clear();
    }
}